<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>演示对象的属性与方法</title>
	</head>
	<body>
		<script>
			var dog = {'name': '牛腩', 'age': 1.5, 'height': '85cm'};
			dog2 = {'name': '萝卜', 'age': 3, 'height': '35cm'};
			console.log(dog);
			
			console.log("dog的已定义的属性有")
			console.log(dog.name);
			console.log(dog.age);
			console.log(dog.height);
			
			console.log("dog对象未定义的属性")
			// 调用未定义的属性.会返回undefined
			console.log(dog.sex);
			// js是一门动态语言.所以可以随时给对象增加属性
			dog.sex = '男'
			console.log(dog.sex);
			
			console.log("dog对象定义方法")
			 
			// 使用匿名函数增加对象的方法
			dog.run = function(){
				// this 代表当前对象.
				console.log(this.name + "在跑");
			}

			dog.eat = function(){
				console.log(this.name + "在吃");
			}
			
			dog2.run = function(){
				// this 代表当前对象.
				console.log(this.name + "在跑");
			}
			
			dog2.eat = function(){
				console.log(this.name + "在吃");
			}
			
			
			function fight(){
				// this指向当前对象
				console.log(this.name + "在战斗");
				console.log("for the lichking!")
			}
			
			dog.fight = fight;
			dog2.fight = fight;
			
			dog.run();
			dog.eat();
			dog2.run();
			dog2.eat();
			
			dog.fight();
			dog2.fight();
			
		</script>
	</body>
</html>
